package com.fieldchain.ex.fa100.ui.trade.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.inter.TradeCallBack;

import java.util.ArrayList;
import java.util.List;

import com.fieldchain.ex.fa100.utils.string.NumberFormate;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/13
 */
public class TradSellAdapter extends RecyclerView.Adapter<TradSellAdapter.ViewHolder> {
    private Context mContext;
    private TradeCallBack callBack;

    private int priceLength;
    private int numberLength;
    public TradSellAdapter(Context mContext) {
        this.mContext = mContext;
    }
    private List<List<Double>> list = new ArrayList<>();

    public void setData(List<List<Double>> list,int priceLength,int numberLength) {
        this.priceLength=priceLength;
        this.numberLength=numberLength;
        if(list==null)list=new ArrayList<>();
        this.list.clear();
        this.list.addAll(list);
        notifyDataSetChanged();
    }
    public void setCallBack(TradeCallBack callBack){
        this.callBack=callBack;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_sell_trade,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final List<Double> bean=list.get(position);
        holder.tvPrice.setText(NumberFormate.m(bean.get(0),priceLength));
        holder.tvNum.setText(NumberFormate.m(bean.get(1),numberLength));

        holder.reaItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(callBack==null)return;
                callBack.onClick(1,position,bean.get(0));
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();

    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private RelativeLayout reaItem;
        private TextView tvPrice;
        private TextView tvNum;
        public ViewHolder(View itemView) {
            super(itemView);
            reaItem = itemView.findViewById(R.id.rea_item);
            tvPrice = itemView.findViewById(R.id.tv_price);
            tvNum = itemView.findViewById(R.id.tv_num);
        }
    }
}
